var status = 0;
var mpoints;
var itemlist = Array(
        Array(4020013, 100),
        Array(4021020, 100),
        Array(4021031, 100),
        Array(4021022, 200),
        Array(4034789, 200),
        Array(4021011, 200),
        Array(4021021, 300),
        Array(4021039, 300),
        Array(4021043,300)
);

function start() {
        status = -1;
        action(1, 0, 0);
}

function action(mode, type, selection) {
        if (mode == -1) cm.dispose();
        else {
                if (status == 0 && mode == 0) {
                        cm.dispose();
                        return;
                } else if (status >= 1 && mode == 0) {
                        cm.sendOk("真的不考虑购买一些东西么？好的,欢迎下次继续光临！");
                        cm.dispose();
                        return;
                }
                if (mode == 1) status++;
                else status--;
                if (status == 0) {
                        mpoints = "请选择您要购买的道具  #rPS：购买前请确认背包有足够的空间。\r\n一旦购买不能反悔！#r#e #n#b";
                        for (var i = 0; i < itemlist.length; i++) {
                                mpoints += "\r\n#b#L" + i + "##v" + itemlist[i][0] + "##z" + itemlist[i][0] + "#　#d需要#r" + itemlist[i][1] + "#d村落贡献#k#l";
                        }
                        cm.sendSimpleS("" + mpoints, 2);
                } else if (status == 1) {
                        cm.sendGetNumber("你选择的商品为#b#v" + itemlist[selection][0] + "#售价为：" + itemlist[selection][1] + "村落贡献/张\r\n请输入你购买的数量", 1, 1,cm.getPlayer().getHyPay(1));
                        choice = selection;
                } else if (status == 2) {
                        fee = selection;
                        money = fee * itemlist[choice][1];
                        if (fee < 0) {
                                cm.sendOk("不能输入0.或者你没有足够的抵用卷支付你要买的数量.!");
                                cm.dispose();
                                return;
                        } else if (cm.getPlayer().getHyPay(1) < money) {
                                cm.sendOk("购买失败，你没有" + money + "村落贡献");
                                cm.dispose();
                                return;
                        }else if(!cm.canHoldSlots(3)){
                                cm.sendOk("请确认背包空间！");
                                cm.dispose();
                                return;
                        }
                         else {
                                cm.getPlayer().addHyPay(money);
                                cm.gainItem(itemlist[choice][0], fee);
                                cm.worldSpouseMessage(0x0F, "[村落恭喜] :玩家:" + "[" + cm.getChar().getName() + "]" + " " + "偷偷的在免费稀有材料处购置了物品！");
                                cm.sendOk("恭喜，购买成功。只要您多多努力也可以变强的！");
                                cm.dispose();
                        }
                }
        }
}